#include "ScalatorAnimator.h"
#include "../../include/ISceneNode.h"

CScalatorAnimator::CScalatorAnimator(vector3dvpos &ScaleIni,vector3dvpos &ScaleFin,u32 Time):ScalIni(ScaleIni),ScalFin(ScaleFin),
TimeToWork(Time),TimeBegin(0)
{
}

CScalatorAnimator::~CScalatorAnimator()
{

}

bool CScalatorAnimator::AnimateNode(u32 Time,ISceneNode *Node)
{
	if (!TimeBegin)
		TimeBegin = Time;

	Elapsed = Time - TimeBegin;

    vPos Alpha = 0;
	if (Elapsed)
		Alpha = (vPos)((vPos)Elapsed) / ((vPos)TimeToWork);

    if (Elapsed <= TimeToWork)
    {
		Node->SetScale(ScalIni.X + ((ScalFin.X - ScalIni.X) * Alpha),
			ScalIni.Y + ((ScalFin.Y - ScalIni.Y) * Alpha),
			ScalIni.Z + ((ScalFin.Z - ScalIni.Z) * Alpha));
	}

	if (Elapsed >= TimeToWork)
	{
		Node->SetScale(ScalFin);
		return true;
	}
	else
		return false;
}
